#pragma once
#include <vector>
#include "sgobject.h"
#include "SgTexture.h"
#include "graphics/GrVector.h"
class CSgMesh :
	public CSgObject
{
public:
	CSgMesh(void);
	~CSgMesh(void);
	void Render();
    void AddVertex(const CGrVector &v) {m_vertices.push_back(v);}
    void AddNormal(const CGrVector &n) {m_normals.push_back(n);}
    void AddTexCoord(const CGrVector &t) {m_tvertices.push_back(t);}
	unsigned int Debugv(){return m_vertices.size();}
	unsigned int Debug(){return m_tvertices.size();}
	void SetTexture(CSgPtr<CSgTexture> texture) {m_tex = texture;}
    void AddTriangleVertex(int v, int n, int t);
	void CSgMesh::AddFlatQuad(int a, int b, int c, int d, int n, int t = -1.0);
	void AddFlatTriangle(int a, int b, int c,  int n, int t = -1.0);
	void AddQuad(int a, int b, int c, int d);
	void CSgMesh::ComputeSmoothNormals();
	void CSgMesh::LoadOBJ(const char *filename);
	int GetNumVertices(void) {return m_vertices.size();}
private:
	std::vector<CGrVector> m_vertices;
	std::vector<CGrVector> m_normals;
	std::vector<CGrVector> m_tvertices;
	CSgPtr<CSgTexture> m_tex;
    struct TV
    {
        int     v;      // Vertex
        int     n;      // Normal
        int     t;      // Texture coordinate
    };

    typedef std::vector<TV> Triangles;
    typedef Triangles::iterator PTV;
	typedef std::vector<CGrVector> Tvertices;
	typedef Tvertices::iterator PTex;
	typedef Tvertices::iterator Norm;
    Triangles       m_triangles;
};
